package com.xhs.repository;

import com.xhs.entity.Content;
import com.xhs.entity.User;
import com.xhs.entity.ViewHistory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * 访问历史数据访问接口
 */
@Repository
public interface ViewHistoryRepository extends JpaRepository<ViewHistory, Long> {
    
    /**
     * 查找用户对特定内容的访问记录
     */
    Optional<ViewHistory> findByUserAndContent(User user, Content content);
    
    /**
     * 检查用户是否已访问某内容
     */
    boolean existsByUserAndContent(User user, Content content);
    
    /**
     * 获取用户的访问历史（分页）
     */
    Page<ViewHistory> findByUserOrderByLastViewedAtDesc(User user, Pageable pageable);
    
    /**
     * 统计内容的访问次数
     */
    long countByContent(Content content);
} 